<?php

function addPro()
{

    $_POST['pubTime']=time();//时间戳
   $pid=insert('pro',$_POST);//获取ID
   if($pid){
    $img=array('pid'=>$pid);//表关系
    if($_FILES){
        $imgs=uploadFile('../uploads/');//上传图片原路径
        foreach ($imgs as $v) {
           thumb('../uploads/'.$v['name'],'../uploads/800/'.$v['name'],800,800);//缩略图两个路径   图片缩略后的新路径
           thumb('../uploads/'.$v['name'],'../uploads/300/'.$v['name'],300,300);
           thumb('../uploads/'.$v['name'],'../uploads/50/'.$v['name'],50,50);
           $img['name']=$v['name'];
           insert('thumb',$img);
        }
        //原路径新路径在同一文件夹（可切换）
alertMsg('添加成功','listPro.php');
//OO
   }

   }else{
        echo '添加失败';
   }
}
// $_POST['pubtime']=time();
// $pid=insert('pro',$_POST);
// if($pid){
//     $img=array();
// }
function delPro($id){
    if (delete('pro',"id={$id}")){
        alertMsg('删除成功','listPro.php');
        }else{
         alertMsg('删除失败','listPro.php');
        }
    }

function editPro($id){
    if(update('pro',$_POST,"id={$id}")){
        alertMsg('编辑成功','listPro.php');
}else{
      alertMsg('编辑失败','listPro.php');
    }
}

function getTotalProPage(){
    return getresnum('select * from pro');
}


function getAllProPage($page,$pagesize){
     $order=isset($_GET['order'])?$_GET['order']:1;
     $keywords=isset($_GET['keywords'])?$_GET['keywords']:'';
     $where=" where pName like '%$keywords%'";
     $offset=($page-1)*$pagesize;
     $sql="select pro.*,cate.cate from pro left join cate on pro.cId=cate.id $where order by $order limit $offset,$pagesize";

    return fetchall($sql);

}

function getGood4($cid){
  $sql='select id,pName,mPrice from pro where cId='.$cid.' limit 0,4';
  return fetchall($sql);

}

function getGood8($cid){
  $sql='select id,pName,mPrice from pro where cId='.$cid.' limit 4,4';
  return fetchall($sql);


}

